//
//  HLNavViewController.m
//  HL-百思不得姐
//
//  Created by admin on 16/5/7.
//  Copyright © 2016年 CHL. All rights reserved.
//

#import "HLNavViewController.h"

@interface HLNavViewController ()<UIGestureRecognizerDelegate>

@end

@implementation HLNavViewController

//只执行一次
+ (void)load
{
    //拿到全局的UINavigationBar
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[self]];
    //只要是通过模型设置(UINavigationItem),都是通过富文本设置
    NSMutableDictionary *dictAttrs = [NSMutableDictionary dictionary];
    dictAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20]; //加粗
    [navBar setTitleTextAttributes:dictAttrs];
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

#pragma mark - 设置返回按钮
//重写系统push方法,设置左边按钮
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) {
        
        //隐藏底部tabBar
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] hightlightImage:[UIImage imageNamed:@"navigationButtonReturnClick"]title:@"返回" target:self action:@selector(backButtonClick)];
    }
    //必须调用系统方法
    [super pushViewController:viewController animated:YES];
}

#pragma mark - 点击返回按钮的点击
- (void)backButtonClick
{
    [self popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
    
    //禁止系统手势
    self.interactivePopGestureRecognizer.enabled = NO;
}

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return  self.childViewControllers.count > 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
